package com.fcl.oschina.model;

import com.fcl.mylibrary.http.HttpClient;
import com.fcl.mylibrary.util.FLog;
import com.fcl.oschina.Constant;
import com.fcl.oschina.entity.BaseReturn;
import com.fcl.oschina.entity.DetailResult;
import com.fcl.oschina.entity.TweetDetailEntity;
import com.fcl.oschina.ui.activity.DetailView;
import com.fcl.oschina.ui.activity.TweetDetailView;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

/**
 * Created by Administrator on 2017/3/21.
 */
public class TweetDetailModel {

    private String TAG = "TweetDetailModel";
    private String mType;
    private int mId;
    private TweetDetailView mView;
    private String  mNextPage="";

    public TweetDetailModel(String type, int id, TweetDetailView view) {
        mType = type;
        mId = id;
        mView = view;
    }

    public void getDetail() {
        String url = Constant.BASE_URL+"action/apiv2/"+mType+"?id="+mId;
        FLog.error(TAG, "detail url:"+url);
        HttpClient client = new HttpClient(url, new HttpClient.ResultListener() {
            @Override
            public void dealResult(String result) {
                Gson gson = new Gson();
                BaseReturn baseReturn = gson.fromJson(result, new TypeToken<BaseReturn<TweetDetailEntity>>(){}.getType());
                if (baseReturn.getCode() == 1) {
                    mView.setDetail((TweetDetailEntity) baseReturn.getResult());

                }
            }
        });
        client.get();
    }


}
